package com.cheers.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.util.StringUtils;

import com.cheers.common.Constants;

public class VerifyUtil {

	public static boolean numberTest(String g) {
		String r = "^[0-9]+$";
		Pattern p = Pattern.compile(r);
		Matcher m = p.matcher(g);
		
		if (StringUtils.isEmpty(g)) {
			return false;
		}
		return m.matches();
	}
	
	public static String mailTest(String g) {
		String r = "^[0-9a-z_][_.0-9a-z-]{0,31}@([0-9a-z][0-9a-z-]{0,30}\\.){1,4}[a-z]{2,4}$";
		Pattern p = Pattern.compile(r);
		Matcher m = p.matcher(g);
		
		if (g==null || g.trim().equals("")) {}//return false
		if (m.find()) {
			if (!g.equals("") && g.indexOf("@")!=-1) {
				int f = g.indexOf("@");
				String h = g.substring(0, f);
				if (h.length()>64 || g.length()>256) {
					return "邮箱好像太长了? 请重新输入吧";
				} else {
					return Constants.OK;
				}
			}
		} else {
			return "邮箱格式不正确,请重新输入";
		}
		
		return Constants.OK;
	}
	
}
